****APPENDIX TABLE F5****

cd "$main_dir/output/tables/appendix_f"

*********************************************************************************************************************************************************************
*********************************************************************************************************************************************************************
*COLUMNS 1-3 - GLOBAL SAMPLE (HARMONIZED DATASET)********************************************************************************************************************
*********************************************************************************************************************************************************************
*********************************************************************************************************************************************************************

global basic 	sex marital religion edu

//--------------------------------------------------------
//Read in relevant datasets
//--------------------------------------------------------

clear
use "$data_dir/clean/harmonized_dataset.dta"

merge m:1 ccode survey_year yob using "$data_dir/raw/lifeexp_variables_data/growth_rate_mpd_var_exp.dta", nogen keepusing(total_growth_rate_obs wgrowth_rate_1 yob_ln_gdppc total_py_growth_rate_obs preyob_growth_rate_5 preyob_growth_rate_10 preyob_growth_rate_15)

fegen subregion_yob = group(subregion yob) if yob!=-99
fegen svy_survey_year = group(survey_year survey)

cap drop sample pre_birth_sample
gen sample = 1 if born_country!=0 & total_growth_rate_obs>=0.9*(age-1) & total_growth_rate_obs!=.
qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if sample==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
gen pre_birth_sample = 1 if e(sample)==1

//--------------------------------------------------------
//Create Table F5 (Columns 1-3)
//--------------------------------------------------------

//Column 1
qui reghdfe trust_govt wgrowth_rate_1 preyob_growth_rate_5 yob_ln_gdppc if pre_birth_sample==1 & total_py_growth_rate_obs>=5 & total_py_growth_rate_obs!=., absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
local list trust_govt wgrowth_rate_1 preyob_growth_rate_5 yob_ln_gdppc
cap drop z*
foreach x of local list {
	egen z`x' = std(`x') if e(sample)==1
}
reghdfe ztrust_govt zwgrowth_rate_1 zpreyob_growth_rate_5 zyob_ln_gdppc if e(sample)==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
outreg2 using table_f5.doc, replace dec(3) nocons addtext(Geographic Unit FE, Country, ///
														Generation FE, N/A, ///
														Survey Year FE, No, ///
														Survey Year FE x Survey FE, Yes, ///
														Subcontinent FE x Cohort FE, Yes, ///
													    Sample, Harmonized) keep(zwgrowth_rate_1 zpreyob_growth_rate_5) 

//Column 2														
qui reghdfe trust_govt wgrowth_rate_1 preyob_growth_rate_10 yob_ln_gdppc if pre_birth_sample==1 & total_py_growth_rate_obs>=10 & total_py_growth_rate_obs!=., absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
local list trust_govt wgrowth_rate_1 preyob_growth_rate_10 yob_ln_gdppc
cap drop z*
foreach x of local list {
	egen z`x' = std(`x') if e(sample)==1
}
reghdfe ztrust_govt zwgrowth_rate_1 zpreyob_growth_rate_10 zyob_ln_gdppc if e(sample)==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
outreg2 using table_f5.doc, append dec(3) nocons addtext(Geographic Unit FE, Country, ///
													   Generation FE, N/A, ///
													   Survey Year FE, No, ///
													   Survey Year FE x Survey FE, Yes, ///
													   Subcontinent FE x Cohort FE, Yes, ///
													   Sample, Harmonized) keep(zwgrowth_rate_1 zpreyob_growth_rate_10) 
	
//Column 3	
qui reghdfe trust_govt wgrowth_rate_1 preyob_growth_rate_15 yob_ln_gdppc if pre_birth_sample==1 & total_py_growth_rate_obs>=15 & total_py_growth_rate_obs!=., absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
local list trust_govt wgrowth_rate_1 preyob_growth_rate_15 yob_ln_gdppc
cap drop z*
foreach x of local list {
	egen z`x' = std(`x') if e(sample)==1
}
reghdfe ztrust_govt zwgrowth_rate_1 zpreyob_growth_rate_15 zyob_ln_gdppc if e(sample)==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
outreg2 using table_f5.doc, append dec(3) nocons addtext(Geographic Unit FE, Country, ///
													   Generation FE, N/A, ///
													   Survey Year FE, No, ///
													   Survey Year FE x Survey FE, Yes, ///
													   Subcontinent FE x Cohort FE, Yes, ///
													   Sample, Harmonized) keep(zwgrowth_rate_1 zpreyob_growth_rate_15)	
														

*****************************************************************************************************************************************************************
*****************************************************************************************************************************************************************
*COLUMNS 4-6 - US SAMPLE (ANES)**********************************************************************************************************************************
*****************************************************************************************************************************************************************
*****************************************************************************************************************************************************************

global basic 	sex marital religion edu ethnicity birth_state
global extra	employment_status occupation income urban
global time 	survey_year age generation
global polit    party partisan

//--------------------------------------------------------
//Read in relevant datasets
//--------------------------------------------------------

clear
use "$data_dir/clean/anes_final.dta"

egen scode_survey_year = group(state_code survey_year)

//--------------------------------------------------------
//Create Table F5 (Columns 4-6)
//--------------------------------------------------------													

//Columns 4-6
local varlist preyob_growth_rate_5 preyob_growth_rate_10 preyob_growth_rate_15
foreach var of local varlist {
	
	qui reghdfe trust_fed_govt wgrowth_rate_1 `var' yob_ln_gdppc, absorb(state_code $time $basic $extra $polit) cluster(yob)
	
	local list trust_fed_govt wgrowth_rate_1 `var' yob_ln_gdppc
	cap drop z*
	foreach x of local list {
		egen z`x' = std(`x') if e(sample)==1
	}
	
	reghdfe ztrust_fed_govt zwgrowth_rate_1 z`var' zyob_ln_gdppc, absorb(state_code $time $basic $extra $polit) cluster(yob)
	outreg2 using table_f5.doc, append dec(3) nocons addtext(Geographic Unit FE, State, ///
														   Generation FE, Yes, ///
														   Survey Year FE, Yes, ///
														   Survey Year FE x Survey FE, N/A, ///
														   Subcontinent FE x Cohort FE, N/A, ///
														   Sample, ANES) keep(zwgrowth_rate_1 z`var') 								
}

